package com.quick.api.config;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Component;

/**
 * @author ：chicunxiang
 * @date ：Created in 2021/3/25 16:44
 * @description：
 * @version: 1.0
 */
@Component
public class DataSourceSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(
                annotationMetadata.getAnnotationAttributes(EnableDBS.class.getName())
        );

        //在这里可以拿到所有注解的信息，可以根据不同注解的和注解的属性来返回不同的class,
        Object object = annotationAttributes.get("value");

        DataSourceConstant.ENABLE_DBS = object != null && Boolean.parseBoolean(object.toString());
        return new String[0];
    }

}
